package com.boc.langxiang.ui.activity.me;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.boc.langxiang.R;
import com.boc.langxiang.net.H5Url;
import com.boc.langxiang.ui.view.webview.ObservableWebView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AboutFlowOutActivity extends MeBaseToolBarActivity {

    @BindView(R.id.owb_me_about_flowout)
    ObservableWebView mWebView;
    @BindView(R.id.progress_bar)
    ProgressBar mProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_flow_out);
        ButterKnife.bind(this);
        setToolBarTitle("关于壹定壹家");
        initWebViews();
    }

    @Override
    protected int setToolBarBackgroundColor() {
        return Color.WHITE;
    }

    @Override
    protected int setToolBarBackImg() {
        return R.drawable.icon_me_left;
    }

    @Override
    protected int setToolBarTitleColor() {
        return Color.BLACK;
    }

    private void initWebViews() {
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.d("url", url);
//                if (url.equals(webUrl)) {
//                    view.loadUrl(url);
//                } else if (url.startsWith("http://imgurl")) {
//                    List<String> imgs = new ArrayList<>();
//                    String photoURL;
//                    if (url.startsWith("http://imgurl01")) {
//                        photoURL = url.replace("http://imgurl01/?", "");
//                    } else if (url.startsWith("http://imgurl02")) {
//                        photoURL = url.replace("http://imgurl02/?", "");
//                    } else {
//                        photoURL = url.replace("http://imgurl/?", "");
//                    }
//
//                    imgs.add(photoURL);
//                    ImagePagerActivity.imageSize = new ImageSize(webView.getMeasuredWidth(), webView.getMeasuredHeight());
//                    ImagePagerActivity.startImagePagerActivity(mContext, imgs, 0);
//                }
                return true;
            }
        });

        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    mProgressBar.setVisibility(View.GONE);
                } else {
                    mProgressBar.setVisibility(View.VISIBLE);
                    mProgressBar.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }
        });



        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setUseWideViewPort(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setLoadsImagesAutomatically(true);
        mWebView.loadUrl(H5Url.ABOUT);
       // mWebView.setScrollViewCallbacks(this);

        /*webUrl = H5Url.ARTICLE_DETAIL + "?id=" + mId;
        mWebView.loadUrl(webUrl);*/
    }

}
